﻿@using Volo.Abp.Users
@using Volo.Abp.UI.Navigation
@using Volo.Abp.Ui.Branding
@using Volo.Abp.Identity
@inject ICurrentUser CurrentUser
@inject IBrandingProvider BrandingProvider
@inject IdentityUserManager UserManager
@model ApplicationMenu
@{
    string name = CurrentUser.UserName;
}
<aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Brand Logo -->
    <a href="~/" class="brand-link">
        <img src="@(string.IsNullOrWhiteSpace(BrandingProvider.LogoUrl) ? "/themes/adminlte/img/AdminLTELogo.png" : BrandingProvider.LogoUrl)"
             alt="AdminLTE Logo"
             class="brand-image img-circle elevation-3"
             style="opacity: .8" width="33" height="33">
        <span class="brand-text font-weight-light">@BrandingProvider.AppName</span>
    </a>


    <!-- Sidebar -->
    <div class="sidebar">
        <!-- Sidebar user (optional) -->
        <div class="user-panel mt-3 pb-3 mb-3 d-flex">
            <div class="image">
                <img src="~/themes/adminlte/img/user2-160x160.jpg" class="img-circle elevation-2" alt="@name">
            </div>
            <div class="info">
                <a href="~/Account/Manage" class="d-block">@name</a>
            </div>
        </div>

        <!-- Sidebar Menu -->
        <nav class="mt-2">
            <ul class="nav nav-pills nav-sidebar flex-column nav-child-indent" data-widget="treeview" role="menu" data-accordion="false">
                <!-- Add icons to the links using the .nav-icon class
                     with font-awesome or any other icon font library -->
                @foreach (var menuItem in Model.Items)
                {
                    if (menuItem.Url == "/") continue;

                    var elementId = string.IsNullOrEmpty(menuItem.ElementId) ? string.Empty : $"id=\"{menuItem.ElementId}\"";
                    var cssClass = string.IsNullOrEmpty(menuItem.CssClass) ? string.Empty : menuItem.CssClass;
                    var disabled = menuItem.IsDisabled ? "disabled" : string.Empty;
                    if (menuItem.IsLeaf)
                    {
                        <li class="nav-item @menuItem.CssClass">
                            <a href="@(menuItem.Url ?? "#")" class="nav-link">
                                <i class="nav-icon @menuItem.Icon"></i> <p>@menuItem.DisplayName</p>
                            </a>
                        </li>
                    }
                    else
                    {
                        var isActive = menuItem.Items.Exists(x => !string.IsNullOrEmpty(x.CssClass) && x.CssClass.Contains("active"));
                        <li class="nav-item has-treeview @(isActive ? "menu-open" : "")">
                            <a href="#" class="nav-link @(isActive ? "active" : "")">
                                <i class="@menuItem.Icon"></i>
                                <p>
                                    @menuItem.DisplayName
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                @foreach (var childMenuItem in menuItem.Items)
                                {
                                    @await Html.PartialAsync("~/Themes/AdminLTE/Components/Menu/_MenuItem.cshtml", childMenuItem)
                                }
                            </ul>
                        </li>
                    }
                }
            </ul>
        </nav>
        <!-- /.sidebar-menu -->
    </div>
</aside>